package com.hjx.service.impl;

import com.hjx.entity.SysMenu;
import com.hjx.entity.SysRoleMenu;
import com.hjx.mapper.SysRoleMenuMapper;
import com.hjx.service.SysRoleMenuService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;
import java.util.Set;

/**
 * <p>Title:</p>
 * <p>Description:</p>
 *
 * @author hjx
 * @date 2020/6/17 - 8:47
 */
@Service
@Transactional
public class SysRoleMenuServiceImpl implements SysRoleMenuService {
    @Resource
    SysRoleMenuMapper sysRoleMenuMapper;

    @Override
    public List<SysMenu> findMenuByRid(String rid) {
        if (!StringUtils.isEmpty(rid) && !StringUtils.isBlank(rid)) {
            return sysRoleMenuMapper.findMenuByRid(rid);
        }
        return null;
    }

    @Override
    public List<SysMenu> findNoGetMenuByRid(String rid) {
        if (!StringUtils.isEmpty(rid) && !StringUtils.isBlank(rid)) {
            return sysRoleMenuMapper.findNoGetMenuByRid(rid);
        }
        return null;
    }

    @Override
    public boolean insertBatch(SysRoleMenu sysRoleMenu) {
        return sysRoleMenuMapper.insertBatch(sysRoleMenu);
    }

    @Override
    public boolean delete(SysRoleMenu sysRoleMenu) {
        Set<String> rmids = sysRoleMenuMapper.findRmidByRid(sysRoleMenu.getRid());
        rmids.removeAll(sysRoleMenu.getRmids());
        return sysRoleMenuMapper.delete(rmids);
    }
}
